#!/bin/sh
#
#  This shell script gives you some examples how to use 
#  the process table (protbl) library.
#

#INCLUDE_DEBUG=1
# Here we include libinclude.sh.
. libinclude.sh

# Here we import the protbl library.
import protbl

# We define the file which contains the table,
# this is simply a csv file with the space or tab as delimiter
# and a header line like:
# 	'# [KEY0] [KEY1] ...'.
TBL_FILE='example.tbl'
echo ' '
echo "That is the table file $TBL_FILE:"
cat $TBL_FILE
echo "----------------"

# This returns the dimensions of the table -> #columns,#rows
echo -n "The dimensions (#columns,#rows) of $TBL_FILE are: "
protbl_dims $TBL_FILE
echo "----------------"

# Here we do a (v)erbose check of the table integrity:
echo 'A verbose check returns: '
protbl_check $TBL_FILE v
echo "----------------"

# We define a function which access to the variables $[VPREFIX]_[KEY].
# The prefix is by default 'tbl'.
MyFunc1 () {
	echo ''
	echo "*** $tbl_login ***"
	echo "uid: $tbl_uid  pwd: $tbl_password"
	echo "gid: $tbl_gid  com: $tbl_comment"
}
MyFunc2 () {
	echo "- $tbl_login has uid: $tbl_uid"
}

# Here we process each data row in $TBL_FILE with MyFunc:
echo "Processing $TBL_FILE with MyFunc1() reads:"
protbl_func $TBL_FILE MyFunc1
echo "----------------"

# Here we process only a selction of the data,
# namely those rows where gid=106!
key='gid'
value='106'
echo "*** Group $key=$value ***"
protbl_func_where $TBL_FILE MyFunc2 $key $value
echo "----------------"

# Here we just 'received' the variables from data row 2:
row=2
protbl_row $TBL_FILE $row
# and access to them:
echo "In data row $row user $tbl_login with uid=$tbl_uid is listed."
echo "----------------"
echo ''
